package com.example.work2

import android.R.attr.button
import android.graphics.Color
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {

    val expert = ProgramExpert()
    var textviewCount = 1

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //区域一
        val buttonToAddText = findViewById<Button>(R.id.btn_addtextview)
        val layout = findViewById<LinearLayout>(R.id.linear_textviews)

        buttonToAddText.setOnClickListener {
            val textView = "This is a new textView:${textviewCount}"
            val newTextView = TextView(this)
            newTextView.text = textView
            newTextView.setTextColor(Color.BLACK)
            layout.addView(newTextView)
            textviewCount = textviewCount+1
        }


        //区域二
        val buttonToConfirm = findViewById<Button>(R.id.btn_confirm)
        buttonToConfirm.setOnClickListener {
            val spinner = findViewById<Spinner>(R.id.language_spinner)
            val selectedFeature = spinner.selectedItem.toString()
            val textView = findViewById<TextView>(R.id.textView1)
            textView.text = expert.getLanguage(selectedFeature)
        }
    }

}